package com.xoa.service.supervision;

import com.xoa.dao.supervision.SupFeedBackReplyMapper;
import com.xoa.model.supervision.SupFeedBackReply;
import com.xoa.model.users.Users;
import com.xoa.util.CookiesUtil;
import com.xoa.util.DateFormat;
import com.xoa.util.ToJson;
import com.xoa.util.common.StringUtils;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.common.wrapper.BaseWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by gsb on 2017/8/7.
 */
@Service
public class SupFeedBackReplyService {
    @Autowired
    private SupFeedBackReplyMapper supFeedBackReplyMapper;

    public BaseWrapper insetrtSupFeedBackReply(SupFeedBackReply SupFeedBackReply, HttpServletRequest request) {
        BaseWrapper baseWrapper=new BaseWrapper();
        if(StringUtils.checkNull(SupFeedBackReply.getContent())){
            baseWrapper.setFlag(false);
            baseWrapper.setStatus(true);
            baseWrapper.setMsg("更新失败");

        }
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users users = SessionUtils.getSessionInfo(request.getSession(),Users.class,new Users(),redisSessionCookie);
        SupFeedBackReply.setCreaterId(users.getUserId());
        SupFeedBackReply.setSid(0);
        SupFeedBackReply.setCreateTime((DateFormat.getCurrentTime()));
        SupFeedBackReply.setFbId(1);
        int num=supFeedBackReplyMapper.insert(SupFeedBackReply);
        if(num>0){
            baseWrapper.setFlag(true);
            baseWrapper.setStatus(true);
            baseWrapper.setMsg("更新成功");
        }

        return baseWrapper;
    }


    public ToJson<SupFeedBackReply> deleteByPrimaryKeySupFeedBackReply(HttpServletRequest request, Integer sid){

       ToJson<SupFeedBackReply> toJson=new ToJson<>();
        if(StringUtils.checkNull(String.valueOf(sid))){
            toJson.setFlag(1);
            toJson.setMsg("删除失败");
        }
        int num=supFeedBackReplyMapper.deleteByPrimaryKey(sid);
        if(num>0){
            toJson.setFlag(0);
            toJson.setMsg("更新成功");
        }
        return toJson;
    }
}
